<template>
  <div class="banner-quote is-zh" @mouseenter="isHover = true" @mouseleave="isHover = false">
    <div class="banner-quote__wrapper container-content-max">
      <div class="banner-quote__left">
        <div class="quote quote-1"></div>
        <div class="quote quote-2"></div>
        <div class="banner-quote__title" v-html="modelValue?.data?.title"></div>
        <div class="banner-quote__label" v-html="modelValue?.data?.label"></div>
      </div>
      <div class="banner-quote__center"></div>
      <div class="banner-quote__right">
        <div class="banner-quote__right__image">
          <img :src="modelValue?.data?.imgSrc" :alt="modelValue?.data?.alt" />
        </div>
      </div>
    </div>

    <Operate v-if="!isPreview" v-model:show="isHover" @handle-edit="showSetting = true" @handle-delete="handleDelete" @handle-copy="handleCopy" @handle-paste="handlePaste"></Operate>
  </div>

  <Setting v-if="!isPreview" v-model:show="showSetting" :data="modelValue"></Setting>
</template>

<script lang="ts" setup> 
import { ref } from 'vue'
import { randomString } from '@/utils/common'
import Operate from '@/common/Operate/index.vue'
import Setting from './setting.vue'


// 定义组件名称
defineOptions({
  name: 'BannerQuote'
})

const props = defineProps({
  modelValue: {
    type: Object,
    default: () => {}
  },

  // 是否预览
  isPreview: {
    type: Boolean,
    default: true
  }
})

const emit = defineEmits(['update:modelValue', 'handleDelete', 'handleCopy', 'handlePaste'])

const handleInit = () => {
  if (props.modelValue && props.modelValue.data) return // 有数据不用初始化
  const data = {
    id: props.modelValue?.id || randomString(),
    type: 'BannerQuote',
    data: {
      title: '<p>About YWIES</p>',
      label: '<p>About YWIES</p>',
      imgSrc: 'https://osswebsite.ycyw.com/media-library/ywies-bj/images/home/ywies-tx.jpg',
      alt: '',
    }
  }
  emit('update:modelValue', data)
} 

const isHover = ref<boolean>(false);
const showSetting = ref<boolean>(false);

const handleDelete = () => {
  emit('handleDelete', props.modelValue.id)
}

const handleCopy = () => {
  emit('handleCopy', props.modelValue)
}

const handlePaste = (type: string) => {
  emit('handlePaste', type)
}

handleInit()
</script>

<style lang="scss" scoped>
.banner-quote {
  position: relative;
}

.banner-quote {
  background: linear-gradient(90deg,#e3e3e6 11%,#ededef 28%,#fff 59%,#e3e3e6) 0 0 no-repeat;
  height: 45.85vw;
  max-height: 880px;
  overflow: hidden;
}

.banner-quote.is-zh .banner-quote__title,.banner-quote.is-zh .banner-quote__title * {
  line-height: 1.4em;
  letter-spacing: .12em;
}

.banner-quote.is-zh .banner-quote__title b,.banner-quote.is-zh .banner-quote__title strong {
  letter-spacing: .05em;
}

.banner-quote.is-zh .banner-quote__label,.banner-quote.is-zh .banner-quote__label * {
  font-style: normal;
  line-height: 1.4em;
  letter-spacing: .12em;
}

.banner-quote__wrapper {
  --max-width: 1744px;
  display: flex;
  position: relative;
  height: 100%;
}

.banner-quote__left {
  width: 42.96875%;
  position: relative;
  z-index: 2;
  flex-shrink: 0;
}

.banner-quote__center {
  position: absolute;
  left: 33.6979%;
  top: 0;
  width: 47.03%;
  height: 100%;
  background: url() no-repeat 50%/cover;
  z-index: 1;
}

.banner-quote__right {
  width: 57.03125%;
  height: 100%;
}

.banner-quote__right__image {
  height: 100%;
  overflow: hidden;
  opacity: 0;
  -webkit-animation: fade-in .8s ease-in-out .6s 1 normal forwards;
  animation: fade-in .8s ease-in-out .6s 1 normal forwards;
}

.banner-quote__right__image img {
  width: 100%;
  height: 100%;
  -o-object-fit: contain;
  object-fit: contain;
  -o-object-position: bottom;
  object-position: bottom;
  transform: translate(5px,3px);
}

.banner-quote .quote {
  position: absolute;
  width: clamp(85px,(100vw - 1280px)/9.614 + 85px,151.57px);
  height: clamp(100px,(100vw - 1280px)/24.54 + 100px,126.08px);
  -webkit-animation: fade-down .8s ease-in-out .4s 1 normal forwards;
  animation: fade-down .8s ease-in-out .4s 1 normal forwards;
  opacity: 0;
  transform: translateY(-20px);
}

@media(max-width: 1279.98px) {
  .banner-quote .quote {
    width:clamp(25px,(100vw - 320px)/16 + 25px,85px);
    height: clamp(25px,(100vw - 320px)/12.8 + 25px,100px);
  }
}

.banner-quote .quote-1 {
  left: 24px;
  top: clamp(40px,(100vw - 1280px)/16.976 + 40px,77.7px);
  background: url() no-repeat 50%/100% auto;
}

@media(max-width: 1279.98px) {
  .banner-quote .quote-1 {
    top:clamp(20px,(100vw - 768px)/25.6 + 20px,40px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote .quote-1 {
    left:0;
    top: 11px;
  }
}

.banner-quote .quote-2 {
  right: clamp(24px,(100vw - 1280px)/21.333 + 24px,54px);
  bottom: clamp(40px,(100vw - 1280px)/84.211 + 40px,47.6px);
  background: url() no-repeat 50%/100% auto;
  -webkit-animation-delay: .8s;
  animation-delay: .8s;
}

@media(max-width: 1279.98px) {
  .banner-quote .quote-2 {
    bottom: clamp(20px,(100vw - 768px)/25.6 + 20px,40px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote .quote-2 {
    right: clamp(8px,(100vw - 320px)/28 + 8px,24px);
    bottom: 11px;
  }
}

.banner-quote__title {
  position: absolute;
  left: clamp(64px,(100vw - 1280px)/13.913 + 64px,110px);
  top: clamp(125px,(100vw - 1280px)/5.912 + 125px,233.25px);
  opacity: 0;
  transform: translateY(-20px);
  -webkit-animation: fade-down .8s ease-in-out .6s 1 normal forwards;
  animation: fade-down .8s ease-in-out .6s 1 normal forwards;
}

@media(max-width: 1279.98px) {
  .banner-quote__title {
    left:clamp(44px,(100vw - 768px)/25.6 + 44px,64px);
    top: clamp(90px,(100vw - 768px)/14.629 + 90px,125px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote__title {
    left:clamp(16px,(100vw - 320px)/16 + 16px,44px);
    top: clamp(40px,(100vw - 320px)/8.96 + 40px,90px);
  }
}

.banner-quote__title,.banner-quote__title * {
  color: #0032a0;
  color: var(--text-color--primary,#0032a0);
  font-size: clamp(28px,(100vw - 1280px)/80 + 28px,36px);
  font-weight: 700;
  line-height: 1.1em;
  white-space: nowrap;
}

@media(max-width: 1279.98px) {
  .banner-quote__title,.banner-quote__title * {
    line-height:1em;
    font-size: clamp(16px,(100vw - 768px)/42.667 + 16px,28px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote__title,.banner-quote__title * {
    font-size:clamp(8px,(100vw - 320px)/56 + 8px,16px);
  }
}

.banner-quote__title b,.banner-quote__title strong {
  font-style: italic;
  font-size: clamp(60px,(100vw - 1280px)/80 + 60px,68px);
}

@media(max-width: 1279.98px) {
  .banner-quote__title b,.banner-quote__title strong {
    font-size:clamp(32px,(100vw - 768px)/18.286 + 32px,60px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote__title b,.banner-quote__title strong {
    font-size:clamp(14px,(100vw - 320px)/24.889 + 14px,32px);
  }
}

.banner-quote__label {
  position: absolute;
  right: 45px;
  bottom: clamp(150px,(100vw - 1280px)/6.4 + 150px,250px);
  opacity: 0;
  transform: translateY(-20px);
  -webkit-animation: fade-down .8s ease-in-out .8s 1 normal forwards;
  animation: fade-down .8s ease-in-out .8s 1 normal forwards;
}

@media(max-width: 1279.98px) {
  .banner-quote__label {
    bottom:clamp(84px,(100vw - 768px)/7.758 + 84px, 150px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote__label {
    right:clamp(0px, (100vw - 320px)/9.956 + 0px, 45px);
    bottom: clamp(36px, (100vw - 320px)/9.333 + 36px, 84px)
  }
}

.banner-quote__label,.banner-quote__label * {
  text-align: right;
  color: #595757;
  font-style: italic;
  font-size: clamp(24px,(100vw - 1280px)/80 + 24px,32px);
  font-weight: 400;
  line-height: 1.1em;
}

@media(max-width: 1279.98px) {
  .banner-quote__label,.banner-quote__label * {
    font-size:clamp(14px,(100vw - 768px)/51.2 + 14px,24px);
  }
}

@media(max-width: 767.98px) {
  .banner-quote__label,.banner-quote__label * {
    font-size:clamp(8px,(100vw - 320px)/74.667 + 8px,14px);
  }
}

@-webkit-keyframes fade-down {
  0% {
    opacity: 0;
    transform: translateY(-30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-down {
  0% {
    opacity: 0;
    transform: translateY(-30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@-webkit-keyframes fade-in {
  0% {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}
</style>
